package com.example.day07_zhongji.fragment;


import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.day07_zhongji.R;
import com.example.day07_zhongji.adapter.ListAdapter;
import com.example.day07_zhongji.base.BaseFragment;
import com.example.day07_zhongji.bean.ListBean;
import com.example.day07_zhongji.presenter.ListPresenter;
import com.example.day07_zhongji.view.ListView;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListFragment extends BaseFragment<ListPresenter> implements ListView {

    @BindView(R.id.re_list)
    RecyclerView mre_lsit;
    private ArrayList<ListBean.DataBean.DatasBean> datasBeans;
    private ListAdapter listAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        Bundle arguments = getArguments();
        int cid = arguments.getInt("cid");
        mPresenter.getdata(cid);
        mre_lsit.setLayoutManager(new LinearLayoutManager(getContext()));
        mre_lsit.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        datasBeans = new ArrayList<>();
        listAdapter = new ListAdapter(getContext(), datasBeans);
        mre_lsit.setAdapter(listAdapter);
    }

    @Override
    protected void initPresenter() {
        mPresenter=new ListPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_list;
    }

    @Override
    public void onSuccess(ListBean data) {
        datasBeans.addAll(data.getData().getDatas());
        listAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
